const { Controller } = require('egg');
const bcrypt = require('bcrypt');

class UserController extends Controller {
  async createMockUser() {
    const { ctx, app } = this;
    // 生成模拟用户名和密码
    const username = 'mock_' + Math.random().toString(36).substring(2, 10);
    const password = '123456';
    const hash = await bcrypt.hash(password, 10);
    try {
      const user = await app.model.User.create({ username, password: hash });
      ctx.body = { code: 0, msg: '模拟用户创建成功', data: { username, password } };
    } catch (e) {
      ctx.body = { code: 1, msg: '创建失败', error: e.message };
    }
  }
}

module.exports = UserController; 